package service;

import dao.ReportDao;
import entity.Report;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReportService {
    private final ReportDao reportDao = new ReportDao();

    public void reportBlog(int blogId, int userId, String reason){
        reportDao.reportBlog(blogId, userId, reason);
    }

    public void banUser(int userId){
        reportDao.banUser(userId);
    }

    public void unbanUser(int userId){
        reportDao.unbanUser(userId);
    }

    public List<Report> getUnreviewedReports() {
        return reportDao.getUnreviewedReports();
    }

    public Map<Integer, Integer> getBlogReportCounts() {
        List<Report> reports = reportDao.getUnreviewedReports();

        //统计每篇文章的举报次数
        Map<Integer, Integer> blogReportCounts = new HashMap<>();
        for (Report report : reports) {
            int blogId = report.getBlogId();
            blogReportCounts.put(blogId, blogReportCounts.getOrDefault(blogId, 0) + 1);
        }
        return blogReportCounts;
    }

    public void auditReport(int reportId) {
        reportDao.updateReportStatus(reportId, "RESOLVED");
    }
}
